package com.xls.commonlibrary.wxapi;


import android.app.Activity;

import com.orhanobut.logger.Logger;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import static com.xls.commonlibrary.wxapi.ConstWx.wxAppId;

public class WxUtil {
    private static volatile WxUtil singleton = null;

    private WxUtil() {
    }

    public static WxUtil getInstance() {
        if (singleton == null) {
            synchronized (WxUtil.class) {
                if (singleton == null) {
                    singleton = new WxUtil();
                }
            }
        }
        return singleton;
    }

    public void loginWechat(Activity activity) {

        Logger.d("=============loginWechat=============");
        // send oauth request
        final IWXAPI api = WXAPIFactory.createWXAPI(activity, wxAppId, false);
        api.registerApp(wxAppId);

        SendAuth.Req req = new SendAuth.Req();
        req.scope = "snsapi_userinfo"; // 只能填 snsapi_userinfo
        req.state = "wechat_sdk_demo_test";

        api.sendReq(req);
    }

    // todo 解绑微信
    public void unbindWechat(){

    }


}
